package ua.com.alus.resvac.crm.stripes.action.search;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import org.apache.log4j.Logger;
import ua.com.alus.resvac.crm.services.spring.BaseService;
import ua.com.alus.resvac.crm.services.spring.SearchService;
import ua.com.alus.resvac.crm.stripes.base.BaseAction;
import ua.com.alus.resvac.crm.util.search.Search;

import java.util.List;

/**
 * Search action
 *
 * @author Usatov Alexey
 */
@UrlBinding("/search/Search.action")
public class SearchAction extends BaseAction {
    private static final Logger LOGGER = Logger.getLogger(SearchAction.class);

    @SpringBean("/search/searchService")
    private SearchService searchService;

    @SpringBean("/base/baseService")
    private BaseService baseService;

    public void setSearchService(SearchService searchService) {
        this.searchService = searchService;
    }

    @DefaultHandler
    @DontValidate
    public Resolution initSearch() {
        return new ForwardResolution("/public/secured/search.jsp");
    }

    private List<Object> searchResult;

    public List<Object> getSearchResult() {
        return searchResult;
    }

    @ValidateNestedProperties({
            @Validate(field = "regionId", required = true),
            @Validate(field = "position", required = true),
            @Validate(field = "searchType", required = true)
    })
    private Search search;


    public Resolution searchInResumes() {
        searchResult = searchService.search(search);
        return new ForwardResolution("/public/secured/search.jsp");
    }

    public BaseService getBaseService() {
        return baseService;
    }

    public Search getSearch() {
        return search;
    }

    public void setSearch(Search search) {
        this.search = search;
    }
}
